package com.my.consumer.rpc.impl;

import com.my.consumer.rpc.HelloFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author marshal
 * @Date 2021-07-20 8:45 PM
 */
@Component
@Slf4j
public class HelloFallback implements FallbackFactory<HelloFeign> {

    @Override
    public HelloFeign create(Throwable cause) {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\n系统:").append("producer");
        sb.append("\n\n错误类型：").append("系统熔断");
        sb.append("\n\n错误信息：").append(cause.getMessage());
        log.error(sb.toString());

        return new HelloFeign() {
            @Override
            public String message(String msg) {
                return "error";
            }
        };
    }
}
